<?php

/**
 * 异步读写mysql
 */
class AsyncMysql
{
	private $db = null;
	private $config = [
		'host' => '127.0.0.1',
	    'port' => 3306,
	    'user' => 'root',
	    'password' => '19900422chq',
	    'database' => 'blog',
	    'charset' => 'utf8',
	    'timeout' => 2, 
	];

	public function __construct(){

		$this->db = new Swoole\Mysql();
	}

	public function query($sql=''){

		$this->db->connect($this->config,function($db,$res) use ($sql){

			if(!$res){
				print_r($db->connect_error);
				exit;
			}

			$db->query($sql,function($db,$res){

				if($res === false){
					print_r($db->error);
					exit;
				}elseif($res === true){
					print_r($res);
				}else{
					print_r($res);
				}

				$db->close();
			});

			
		});
	}

	public function excute(){

	}

}

$db = new AsyncMysql();
$db->query('select * from cms_admin where 1');